package main;

import java.lang.reflect.Modifier;

import com.model.Student;

public class ReflectionClass {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
// 1. GET CLASS OBJECT		
		
		// get class object (know the name of class at compile time)
		Class<Student> reflectionClass = Student.class;
		
		//get class object (don't know the name of class at compile time)
		String classPath = "com.model.Student";
		try {
			@SuppressWarnings("unused")
			Class<?> reflectionClass1 = Class.forName(classPath);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			System.out.println("Class not found!!!");
			e.printStackTrace();
		}
		
// 2. GET CLASS NAME
		
		// get class name
		String fullClassName = reflectionClass.getName(); //full path
		System.out.println("Full class name: " + fullClassName);
		
		// just get only class name
		String className = reflectionClass.getSimpleName();
		System.out.println("Simple class name: " + className);
		
// 3. GET CLASS MODIFIERS
			
		int classModifier = reflectionClass.getModifiers();
		
		// get class modifier
		System.out.println("Modifier of class:");
		System.out.println("\tisPublic: " + Modifier.isPublic(classModifier));
		System.out.println("\tisInterface: " + Modifier.isInterface(classModifier));
		System.out.println("\tisStatic: " + Modifier.isStatic(classModifier));
		
// 4. GET PACKAGE INFO
		
		Package packageInfo = reflectionClass.getPackage();
		System.out.println(packageInfo);
		
// 5. GET SUPPER CLASS
		
		Class<?> supperClass = reflectionClass.getSuperclass();
		System.out.println("Supper class: " + supperClass.getName());
		
// 6. GET IMPLEMENTED INTERFACES
		
		Class<?>[] interfaces = reflectionClass.getInterfaces();
		for(Class<?> intf : interfaces){
			System.out.println("Implemented interface: " + intf.getName());
		}
	}

}
